package com.example.administrator.hybird_weview_js;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

public class MainActivity extends Activity {

    private WebView web;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        initViews();

    }

    /**
     * 初始化控件
     */
    @SuppressLint("JavascriptInterface")
    private void initViews() {
        web = (WebView) this.findViewById(R.id.web);
//        web.setWebViewClient(new );\
        final String tUrl = "http://www.baidu.com";
        web.setWebViewClient(new WebViewClient() {
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                view.loadUrl(url);
                return true;
            }
        });
        WebSettings webSettings = web.getSettings();
        webSettings.setJavaScriptEnabled(true);
        web.addJavascriptInterface(new NativeJavaScript(this),"NativeJavaScript");
        //file:///android_asset/
        web.loadUrl("file:///android_asset/web/index.html");
    }


}
